package no18.javaio;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;

/**
 * 输出到文件
 * 
 * @author gao
 * 
 */
public class FileOutput {
	private final static String IN_FILE_NAME = "D:/work/project/complex/complex.thinkinjava/src/main/java/no18/javaio/test.txt";
	private final static String OUT_FILE_NAME = "D:/work/project/complex/complex.thinkinjava/src/main/java/no18/javaio/output.txt";

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new StringReader(
				BufferedInputFile.read(IN_FILE_NAME)));
		// 创建一个与指定文件连接的FileWriter
		// 使用BufferedWriter将其包装起来用以缓冲输出
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				OUT_FILE_NAME)));
		// 快捷写法
		// PrintWriter out = new PrintWriter(OUT_FILE_NAME);
		int lineCount = 1;
		String s;
		while ((s = in.readLine()) != null) {
			out.println(lineCount++ + ":" + s);
		}
		// 显示调用close()方法,以清空缓冲区
		out.close();
		in.close();
	}

}
